package com.xywl.escort.adapter;

import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xywl.escort.R;
import com.xywl.escort.bean.MarketDataBean;
import com.xywl.escort.utils.NumberFormatUtils;
import com.xywl.escort.widget.GlideApp;

import java.util.List;

/**
 * Created by 32422 on 2018/5/4.
 */

public class MarketAdapter extends BaseQuickAdapter<MarketDataBean, BaseViewHolder> {
    public MarketAdapter(int layoutResId, @Nullable List<MarketDataBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, MarketDataBean item) {
        if (null != item) {
            ImageView imgShop = helper.getView(R.id.img_shop);
            GlideApp.with(mContext)
                    .load(item.imageUrl)
                    .centerCrop()
                    .placeholder(R.mipmap.icon_default_picture)
                    .into(imgShop);
            helper.setText(R.id.text_title, item.spuName);
            if (null != item.originalPrice) {
                double originalPrice = item.originalPrice.doubleValue();
                String strPrice = NumberFormatUtils.getInstance().format(originalPrice);
                TextView textOriginalPrice = helper.getView(R.id.text_original_price);
                textOriginalPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
                textOriginalPrice.setText("原价:" + strPrice);
            }
            if (null != item.price) {
                double price = item.price.doubleValue();
                String strPrice = NumberFormatUtils.getInstance().format(price);
                helper.setText(R.id.text_price, "现价:" + strPrice);
            }
            ImageView imageProprietary = helper.getView(R.id.image_proprietary);
            if (item.type == 1) {
                imageProprietary.setVisibility(View.VISIBLE);
            } else {
                imageProprietary.setVisibility(View.GONE);
            }
        }
    }
}
